//二叉树的直径
class Solution {
public:
    int res=0;
    int diameterOfBinaryTree(TreeNode* root) 
    {
        getchildlegth(root);
        return res-1;
    }
    int getchildlegth(TreeNode* root)
    {
        if(root==nullptr) return 0;
        int left=getchildlegth(root->left);
        int right=getchildlegth(root->right);
        res=max(res,left+right+1);
        return 1+max(left,right);
    }
};
//二叉树的最大深度
class Solution {
public:
    int maxDepth(TreeNode* root) 
    {
        if(root==nullptr) return 0;
        //采用后序遍历
        int left=maxDepth(root->left);
        int right=maxDepth(root->right);
        int res=1+max(left,right);
        return res; 
    }
};

//二叉树的最小深度
class Solution {
public:
    int minDepth(TreeNode* root) 
    {
        if(root==nullptr) return 0;
        int leftdeep=minDepth(root->left);
        int rightdeep=minDepth(root->right);
        if(root->left==nullptr && root->right!=nullptr)
        {
            return 1+rightdeep;
        }
        else if(root->left!=nullptr && root->right==nullptr)
        {
            return 1+leftdeep;
        }
        else
        {
            return 1+min(leftdeep,rightdeep);
        }
    }
};
//完全二叉树的节点个数

class Solution {
public:
    int countNodes(TreeNode* root) 
    {
        if(root==nullptr) return 0;
        int leftsize=countNodes(root->left);
        int rightsize=countNodes(root->right);
        return 1+leftsize+rightsize;
    }
};
